package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.ysd.entity.Admin;
import com.ysd.util.DBManager;

public class AdminDaoImpl {
	public Admin getAdminByUsername(String username) {
		Admin admin = null;
		Connection conn = DBManager.grtConnection();
		Statement st = null;
		ResultSet rs = null;
		
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from admin where username='"+username+"'");
			while(rs.next()) {
				int id = rs.getInt(1);
				String uname = rs.getString(2);
				String password = rs.getString(3);
				admin = new Admin(id,uname,password);
			}
			return admin;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} finally {
			DBManager.closeAll(conn, st, rs);
		}
		
	}
}
